const fs = require('fs');
const { createCanvas } = require('canvas');

function generateSpotImage(filename, text, color) {
  const canvas = createCanvas(800, 600);
  const ctx = canvas.getContext('2d');

  // 设置背景色
  ctx.fillStyle = color;
  ctx.fillRect(0, 0, 800, 600);

  // 添加文字
  ctx.fillStyle = '#ffffff';
  ctx.font = 'bold 48px Arial';
  ctx.textAlign = 'center';
  ctx.textBaseline = 'middle';
  ctx.fillText(text, 400, 300);

  // 保存图片
  const buffer = canvas.toBuffer('image/jpeg');
  fs.writeFileSync(filename, buffer);
  console.log(`Generated ${filename}`);
}

// 确保spots目录存在
if (!fs.existsSync('images/spots')) {
  fs.mkdirSync('images/spots', { recursive: true });
}

// 生成西湖景点图片
generateSpotImage('images/spots/xihu1.jpg', '西湖 - 断桥残雪', '#4A90E2');
generateSpotImage('images/spots/xihu2.jpg', '西湖 - 平湖秋月', '#50E3C2');
generateSpotImage('images/spots/xihu3.jpg', '西湖 - 三潭印月', '#F5A623'); 